using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VVLEXPORT
    {
        public DataRow Convert2VLEXPORT(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryVLEXPORT(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["VLEMANDANT"] = " ".PadRight(2 ); 
         dwReturn["VLELAND"] = " ".PadRight(3 ); 
         dwReturn["VLEVORGANG"] = " ".PadRight(2 ); 
         dwReturn["VLEVERSART"] = " ".PadRight(3 ); 
         dwReturn["VLESPED"] = " ".PadRight(3 ); 
         dwReturn["VLEKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["VLENEUB"] = " ".PadRight(8 ); 
         dwReturn["VLENEUD"] = " ".PadRight(0 ); 
         dwReturn["VLEAENB"] = " ".PadRight(8 ); 
         dwReturn["VLEAEND"] = " ".PadRight(0 ); 
         dwReturn["VLEAENZL"] = " ".PadRight(0 ); 
         dwReturn["VLEDRPROG1"] = " ".PadRight(8 ); 
         dwReturn["VLEKOPIEN1"] = " ".PadRight(1 ); 
         dwReturn["VLEFACHNR1"] = " ".PadRight(2 ); 
         dwReturn["VLEPARAM1"] = " ".PadRight(20 ); 
         dwReturn["VLEWERTAB1"] = " ".PadRight(0 ); 
         dwReturn["VLEDRPROG2"] = " ".PadRight(8 ); 
         dwReturn["VLEKOPIEN2"] = " ".PadRight(1 ); 
         dwReturn["VLEFACHNR2"] = " ".PadRight(2 ); 
         dwReturn["VLEPARAM2"] = " ".PadRight(20 ); 
         dwReturn["VLEWERTAB2"] = " ".PadRight(0 ); 
         dwReturn["VLEDRPROG3"] = " ".PadRight(8 ); 
         dwReturn["VLEKOPIEN3"] = " ".PadRight(1 ); 
         dwReturn["VLEFACHNR3"] = " ".PadRight(2 ); 
         dwReturn["VLEPARAM3"] = " ".PadRight(20 ); 
         dwReturn["VLEWERTAB3"] = " ".PadRight(0 ); 
         dwReturn["VLEDRPROG4"] = " ".PadRight(8 ); 
         dwReturn["VLEKOPIEN4"] = " ".PadRight(1 ); 
         dwReturn["VLEFACHNR4"] = " ".PadRight(2 ); 
         dwReturn["VLEPARAM4"] = " ".PadRight(20 ); 
         dwReturn["VLEWERTAB4"] = " ".PadRight(0 ); 
         dwReturn["VLEDRPROG5"] = " ".PadRight(8 ); 
         dwReturn["VLEKOPIEN5"] = " ".PadRight(1 ); 
         dwReturn["VLEFACHNR5"] = " ".PadRight(2 ); 
         dwReturn["VLEPARAM5"] = " ".PadRight(20 ); 
         dwReturn["VLEWERTAB5"] = " ".PadRight(0 ); 
         dwReturn["VLEDRPROG6"] = " ".PadRight(8 ); 
         dwReturn["VLEKOPIEN6"] = " ".PadRight(1 ); 
         dwReturn["VLEFACHNR6"] = " ".PadRight(2 ); 
         dwReturn["VLEPARAM6"] = " ".PadRight(20 ); 
         dwReturn["VLEWERTAB6"] = " ".PadRight(0 ); 
         dwReturn["VLEDRPROG7"] = " ".PadRight(8 ); 
         dwReturn["VLEKOPIEN7"] = " ".PadRight(1 ); 
         dwReturn["VLEFACHNR7"] = " ".PadRight(2 ); 
         dwReturn["VLEPARAM7"] = " ".PadRight(20 ); 
         dwReturn["VLEWERTAB7"] = " ".PadRight(0 ); 
         dwReturn["VLEDRPROG8"] = " ".PadRight(8 ); 
         dwReturn["VLEKOPIEN8"] = " ".PadRight(1 ); 
         dwReturn["VLEFACHNR8"] = " ".PadRight(2 ); 
         dwReturn["VLEPARAM8"] = " ".PadRight(20 ); 
         dwReturn["VLEWERTAB8"] = " ".PadRight(0 ); 
         dwReturn["VLEFILLER"] = " ".PadRight(23 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapVLEXPORT(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveVLEXPORT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryVLEXPORT(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapVLEXPORT(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertVLEXPORT(dwLocal, ITXDBVERSION);
            }
            UpdateVLEXPORT(dwLocal);
        }
        public void InsertVLEXPORT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO VLEXPORT(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryVLEXPORT(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM VLEXPORT WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM VLEXPORT  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "VLEXPORT";
            Return = Result;
            return Return;
        }
        public void DeleteVLEXPORT(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM VLEXPORT   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateVLEXPORT(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE VLEXPORT SET "
                    +"VLEMANDANT= :VLEMANDANT,"
                    +"VLELAND= :VLELAND,"
                    +"VLEVORGANG= :VLEVORGANG,"
                    +"VLEVERSART= :VLEVERSART,"
                    +"VLESPED= :VLESPED,"
                    +"VLEKUNDNR= :VLEKUNDNR,"
                    +"VLENEUB= :VLENEUB,"
                    +"VLENEUD= :VLENEUD,"
                    +"VLEAENB= :VLEAENB,"
                    +"VLEAEND= :VLEAEND,"
                    +"VLEAENZL= :VLEAENZL,"
                    +"VLEDRPROG1= :VLEDRPROG1,"
                    +"VLEKOPIEN1= :VLEKOPIEN1,"
                    +"VLEFACHNR1= :VLEFACHNR1,"
                    +"VLEPARAM1= :VLEPARAM1,"
                    +"VLEWERTAB1= :VLEWERTAB1,"
                    +"VLEDRPROG2= :VLEDRPROG2,"
                    +"VLEKOPIEN2= :VLEKOPIEN2,"
                    +"VLEFACHNR2= :VLEFACHNR2,"
                    +"VLEPARAM2= :VLEPARAM2,"
                    +"VLEWERTAB2= :VLEWERTAB2,"
                    +"VLEDRPROG3= :VLEDRPROG3,"
                    +"VLEKOPIEN3= :VLEKOPIEN3,"
                    +"VLEFACHNR3= :VLEFACHNR3,"
                    +"VLEPARAM3= :VLEPARAM3,"
                    +"VLEWERTAB3= :VLEWERTAB3,"
                    +"VLEDRPROG4= :VLEDRPROG4,"
                    +"VLEKOPIEN4= :VLEKOPIEN4,"
                    +"VLEFACHNR4= :VLEFACHNR4,"
                    +"VLEPARAM4= :VLEPARAM4,"
                    +"VLEWERTAB4= :VLEWERTAB4,"
                    +"VLEDRPROG5= :VLEDRPROG5,"
                    +"VLEKOPIEN5= :VLEKOPIEN5,"
                    +"VLEFACHNR5= :VLEFACHNR5,"
                    +"VLEPARAM5= :VLEPARAM5,"
                    +"VLEWERTAB5= :VLEWERTAB5,"
                    +"VLEDRPROG6= :VLEDRPROG6,"
                    +"VLEKOPIEN6= :VLEKOPIEN6,"
                    +"VLEFACHNR6= :VLEFACHNR6,"
                    +"VLEPARAM6= :VLEPARAM6,"
                    +"VLEWERTAB6= :VLEWERTAB6,"
                    +"VLEDRPROG7= :VLEDRPROG7,"
                    +"VLEKOPIEN7= :VLEKOPIEN7,"
                    +"VLEFACHNR7= :VLEFACHNR7,"
                    +"VLEPARAM7= :VLEPARAM7,"
                    +"VLEWERTAB7= :VLEWERTAB7,"
                    +"VLEDRPROG8= :VLEDRPROG8,"
                    +"VLEKOPIEN8= :VLEKOPIEN8,"
                    +"VLEFACHNR8= :VLEFACHNR8,"
                    +"VLEPARAM8= :VLEPARAM8,"
                    +"VLEWERTAB8= :VLEWERTAB8,"
                    +"VLEFILLER= :VLEFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("VLEMANDANT", OracleType.NVarChar).Value = dwData["VLEMANDANT"].ToString(); 
          or1.Parameters.Add("VLELAND", OracleType.NVarChar).Value = dwData["VLELAND"].ToString(); 
          or1.Parameters.Add("VLEVORGANG", OracleType.NVarChar).Value = dwData["VLEVORGANG"].ToString(); 
          or1.Parameters.Add("VLEVERSART", OracleType.NVarChar).Value = dwData["VLEVERSART"].ToString(); 
          or1.Parameters.Add("VLESPED", OracleType.NVarChar).Value = dwData["VLESPED"].ToString(); 
          or1.Parameters.Add("VLEKUNDNR", OracleType.NVarChar).Value = dwData["VLEKUNDNR"].ToString(); 
          or1.Parameters.Add("VLENEUB", OracleType.NVarChar).Value = dwData["VLENEUB"].ToString(); 
          or1.Parameters.Add("VLENEUD", OracleType.NVarChar).Value = dwData["VLENEUD"].ToString(); 
          or1.Parameters.Add("VLEAENB", OracleType.NVarChar).Value = dwData["VLEAENB"].ToString(); 
          or1.Parameters.Add("VLEAEND", OracleType.NVarChar).Value = dwData["VLEAEND"].ToString(); 
          or1.Parameters.Add("VLEAENZL", OracleType.NVarChar).Value = dwData["VLEAENZL"].ToString(); 
          or1.Parameters.Add("VLEDRPROG1", OracleType.NVarChar).Value = dwData["VLEDRPROG1"].ToString(); 
          or1.Parameters.Add("VLEKOPIEN1", OracleType.NVarChar).Value = dwData["VLEKOPIEN1"].ToString(); 
          or1.Parameters.Add("VLEFACHNR1", OracleType.NVarChar).Value = dwData["VLEFACHNR1"].ToString(); 
          or1.Parameters.Add("VLEPARAM1", OracleType.NVarChar).Value = dwData["VLEPARAM1"].ToString(); 
          or1.Parameters.Add("VLEWERTAB1", OracleType.NVarChar).Value = dwData["VLEWERTAB1"].ToString(); 
          or1.Parameters.Add("VLEDRPROG2", OracleType.NVarChar).Value = dwData["VLEDRPROG2"].ToString(); 
          or1.Parameters.Add("VLEKOPIEN2", OracleType.NVarChar).Value = dwData["VLEKOPIEN2"].ToString(); 
          or1.Parameters.Add("VLEFACHNR2", OracleType.NVarChar).Value = dwData["VLEFACHNR2"].ToString(); 
          or1.Parameters.Add("VLEPARAM2", OracleType.NVarChar).Value = dwData["VLEPARAM2"].ToString(); 
          or1.Parameters.Add("VLEWERTAB2", OracleType.NVarChar).Value = dwData["VLEWERTAB2"].ToString(); 
          or1.Parameters.Add("VLEDRPROG3", OracleType.NVarChar).Value = dwData["VLEDRPROG3"].ToString(); 
          or1.Parameters.Add("VLEKOPIEN3", OracleType.NVarChar).Value = dwData["VLEKOPIEN3"].ToString(); 
          or1.Parameters.Add("VLEFACHNR3", OracleType.NVarChar).Value = dwData["VLEFACHNR3"].ToString(); 
          or1.Parameters.Add("VLEPARAM3", OracleType.NVarChar).Value = dwData["VLEPARAM3"].ToString(); 
          or1.Parameters.Add("VLEWERTAB3", OracleType.NVarChar).Value = dwData["VLEWERTAB3"].ToString(); 
          or1.Parameters.Add("VLEDRPROG4", OracleType.NVarChar).Value = dwData["VLEDRPROG4"].ToString(); 
          or1.Parameters.Add("VLEKOPIEN4", OracleType.NVarChar).Value = dwData["VLEKOPIEN4"].ToString(); 
          or1.Parameters.Add("VLEFACHNR4", OracleType.NVarChar).Value = dwData["VLEFACHNR4"].ToString(); 
          or1.Parameters.Add("VLEPARAM4", OracleType.NVarChar).Value = dwData["VLEPARAM4"].ToString(); 
          or1.Parameters.Add("VLEWERTAB4", OracleType.NVarChar).Value = dwData["VLEWERTAB4"].ToString(); 
          or1.Parameters.Add("VLEDRPROG5", OracleType.NVarChar).Value = dwData["VLEDRPROG5"].ToString(); 
          or1.Parameters.Add("VLEKOPIEN5", OracleType.NVarChar).Value = dwData["VLEKOPIEN5"].ToString(); 
          or1.Parameters.Add("VLEFACHNR5", OracleType.NVarChar).Value = dwData["VLEFACHNR5"].ToString(); 
          or1.Parameters.Add("VLEPARAM5", OracleType.NVarChar).Value = dwData["VLEPARAM5"].ToString(); 
          or1.Parameters.Add("VLEWERTAB5", OracleType.NVarChar).Value = dwData["VLEWERTAB5"].ToString(); 
          or1.Parameters.Add("VLEDRPROG6", OracleType.NVarChar).Value = dwData["VLEDRPROG6"].ToString(); 
          or1.Parameters.Add("VLEKOPIEN6", OracleType.NVarChar).Value = dwData["VLEKOPIEN6"].ToString(); 
          or1.Parameters.Add("VLEFACHNR6", OracleType.NVarChar).Value = dwData["VLEFACHNR6"].ToString(); 
          or1.Parameters.Add("VLEPARAM6", OracleType.NVarChar).Value = dwData["VLEPARAM6"].ToString(); 
          or1.Parameters.Add("VLEWERTAB6", OracleType.NVarChar).Value = dwData["VLEWERTAB6"].ToString(); 
          or1.Parameters.Add("VLEDRPROG7", OracleType.NVarChar).Value = dwData["VLEDRPROG7"].ToString(); 
          or1.Parameters.Add("VLEKOPIEN7", OracleType.NVarChar).Value = dwData["VLEKOPIEN7"].ToString(); 
          or1.Parameters.Add("VLEFACHNR7", OracleType.NVarChar).Value = dwData["VLEFACHNR7"].ToString(); 
          or1.Parameters.Add("VLEPARAM7", OracleType.NVarChar).Value = dwData["VLEPARAM7"].ToString(); 
          or1.Parameters.Add("VLEWERTAB7", OracleType.NVarChar).Value = dwData["VLEWERTAB7"].ToString(); 
          or1.Parameters.Add("VLEDRPROG8", OracleType.NVarChar).Value = dwData["VLEDRPROG8"].ToString(); 
          or1.Parameters.Add("VLEKOPIEN8", OracleType.NVarChar).Value = dwData["VLEKOPIEN8"].ToString(); 
          or1.Parameters.Add("VLEFACHNR8", OracleType.NVarChar).Value = dwData["VLEFACHNR8"].ToString(); 
          or1.Parameters.Add("VLEPARAM8", OracleType.NVarChar).Value = dwData["VLEPARAM8"].ToString(); 
          or1.Parameters.Add("VLEWERTAB8", OracleType.NVarChar).Value = dwData["VLEWERTAB8"].ToString(); 
          or1.Parameters.Add("VLEFILLER", OracleType.NVarChar).Value = dwData["VLEFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
